<?php
/**
 * Created by PhpStorm.
 * User: yhg97p
 * Date: 2016/6/28
 * Time: 17:11
 */
include __DIR__ . '/vendor/autoload.php';
date_default_timezone_set('PRC');
use EasyWeChat\Server\BadRequestException;
use EasyWeChat\Foundation\Application;

$options = [
    'debug' => true,
    'app_id' => 'wx1cd5b8a5438c2130',
    'secret' => 'd65240fc907d1aad8d3386ea60d2726e ',
    'token' => 'w0Q52Arls2S9T2qlsRA215q09q2L9R2z',
    'aes_key' => 'Veg9MEUnmztEYnsJgniStH3ifk8O0RmlBQKzvUuwHXE',


    'guzzle' => [
        'timeout' => 3.0, // 超时时间（秒）
        'verify' => false, // 关掉 SSL 认证（强烈不建议！！！）
    ],
    'log' => [
        'level' => 'debug',
        'file' => __DIR__ . '/log/' . date('Y-m-d') . '.log',
    ],
];

$app = new Application($options);
$server = $app->server;
$server->setMessageHandler(function ($message) {
    $openid = $message->FromUserName;
    switch ($message->MsgType) {
        case 'event':
            switch ($message->Event) {
                case 'subscribe':   //订阅
                    return '';
                    break;
                case 'unsubscribe': //取消订阅
                    break;
                default:
                    return '';
                    break;
            }
            break;
        case 'text':    //用户发送文本消息
            //do something
            return "http://".$_SERVER['SERVER_NAME']."/index.php?s=/Home/Share/index.html";
            break;
    }
});
$response = $server->serve();
return $response->send();